using System;
using System.Web;

namespace SpiderMaster.AspNet
{
    public sealed partial class TradingCenterHttpApplication
    {
        private static bool s_InitializedAlready = false;
        private static object s_Lock = new object();

        /// <summary> Should Run once, only on startup and reboot.
        /// </summary>
        internal sealed class FirstRequestInitialization
        {
            // Initialize only on the first request
            internal static void Initialize(HttpContext context)
            {
                if (s_InitializedAlready)
                    return;

                lock (s_Lock)
                {
                    if (s_InitializedAlready)
                        return;

                    s_InitializedAlready = true;
                }
            }
            void Application_BeginRequest(Object source, EventArgs e)
            {
                HttpApplication app = (HttpApplication)source;
                HttpContext context = app.Context;

                // Attempt to peform first request initialization

                FirstRequestInitialization.Initialize(context);
            }
        }
    }
}